package com.example.satoken.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.satoken.DO.SysUserDo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author chenhh
 * @version v1.0
 * @date 2025/5/12 16:30
 */
@Mapper
public interface SysUserMapper extends BaseMapper<SysUserDo> {

    @Select("SELECT DISTINCT m.perms " +
            "FROM sys_user_role ur " +
            "LEFT JOIN sys_role_menu rm ON ur.role_id = rm.role_id " +
            "LEFT JOIN sys_menu m ON rm.menu_id = m.id " +
            "WHERE ur.user_id = #{userId} AND m.perms IS NOT NULL")
    List<String> selectMenuPermsByUserId(Long userId);

    @Select("SELECT DISTINCT r.role_key " +
            "FROM sys_user_role ur " +
            "LEFT JOIN sys_role r ON ur.role_id = r.id " +
            "WHERE ur.user_id = #{userId}")
    List<String> selectRoleKeysByUserId(Long userId);
}
